package com.yuanchu.goods.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.goods.dto.QueryCommentParamsDto;
import com.yuanchu.goods.entity.YoshopCommentEntity;
import com.yuanchu.goods.service.YoshopCommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 商品评价记录表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 02:17:44
 */
@RestController
@RequestMapping("comment")
public class YoshopCommentController {
    @Resource
    private YoshopCommentService yoshopCommentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam(required = false) QueryCommentParamsDto params) {
        if (params == null){
            params = new QueryCommentParamsDto();
        }
        PageResult<YoshopCommentEntity> page = yoshopCommentService.queryCommentParams(params);
        Map<String, Object> map = new HashMap<>();
        map.put("list", page);
        return R.ok().put("data", map);
    }

    @GetMapping("/all")
    public R all() {
        List<YoshopCommentEntity> page = yoshopCommentService.queryAllComments();
        Map<String, Object> map = new HashMap<>();
        map.put("list", page);
        return R.ok().put("page", map);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{commentId}")
    public R info(@PathVariable("commentId") Integer commentId) {
        YoshopCommentEntity yoshopComment = yoshopCommentService.getById(commentId);

        return R.ok().put("yoshopComment", yoshopComment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody YoshopCommentEntity yoshopComment) {
        yoshopCommentService.save(yoshopComment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody YoshopCommentEntity yoshopComment) {
        yoshopCommentService.updateById(yoshopComment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] commentIds) {
        yoshopCommentService.removeByIds(Arrays.asList(commentIds));

        return R.ok();
    }

}
